/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author HuuTai_it
 */
public class Setting extends Canvas{ 
      
    private Image setting = Image.createImage("/MyPicture/settingscreen.png");
    private Image choiceSound = Image.createImage("/MyPicture/choice1.png");
    private Image choiceMode = Image.createImage("/MyPicture/choice2.png");
    
    private Control control;    
    
    private boolean enableSound = true;
    
    public Setting(Control control) throws Exception {
        
        this.control = control;
        setFullScreenMode(true);
    }
    
    public void paint(Graphics g) {
        
        g.drawImage(setting, 0, 0, Sprite.TRANS_NONE);
        
        if(enableSound)
            g.drawImage(choiceSound, 47, 128, Sprite.TRANS_NONE);
        
        g.drawImage(choiceMode, 35, 190 + 25 * (control.difficulties - 1), Sprite.TRANS_NONE);
    }
    
    public void keyPressed(int keyCode) {
        
        switch(getGameAction(keyCode)) {
            
            case UP:
                if(control.difficulties-- == 1)
                    control.difficulties = 3;
            repaint();
                break;
                
            case DOWN:
                if(control.difficulties++ == 3)
                    control.difficulties = 1;
            repaint();
                break;
                
            case LEFT:   
            case RIGHT:                  
                if(enableSound)
                    enableSound = false;
                else
                    enableSound = true;
                repaint();
                break;
                
            case FIRE:
                
                control.life = 4 - control.difficulties;
                control.showMainMenu();
                break;
        }
    }    
}